const BASE_URL = "https://919api.71.dianchuiguan.com.cn/v1"
// 接口域名：https://919api.71.dianchuiguan.com.cn
// 静态资源域名：https://919admin.71.dianchuiguan.com.cn
// 文件上传接口：https://919admin.71.dianchuiguan.com.cn/api/common/upload
function request(url, method, data) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASE_URL + url,
			method: method || 'POST',
			data: data,
			header: {
				'Content-Type': 'application/json', // 设置请求头
				Authorization: uni.getStorageSync('token') || ''
			},
			success: (res) => {
				// console.log(res.header.Authorization);
				// if (res.header.Authorization) {
				// 	uni.setStorageSync('token')
				// }
				if (res.data.code == 1) {
					resolve(res);
				} else if (res.data.code == 401) {
					uni.$u.toast("没登陆")
					uni.redirectTo({
						url: '/pages/login/login'
					})
				} else {
					reject(res)
				}
			},
			fail: (err) => {
				reject(err);
			},
		});
	});
}
export default request;